<template>
  <view class="page-usercenter">
    <view class="header">
      <view class="fly-card">
        <view class="item" @tap="gotoPage('/packageA/user/info')">
          <view class="thumb">
            <van-image round width="100rpx" height="100rpx" :src="user_info.avatar"></van-image>
          </view>
          <view class="content">
            <view class="title">{{user_info.name ?  user_info.name :user_info.userName}}</view>
            <view class="desc">
              <view class="company">xxxxx公司 车队长</view>
              <text>{{user_info.phone}}</text>
            </view>
          </view>
          <van-icon name="arrow" />
        </view>
      </view>
		</view>
    <view class="main">
      <van-cell-group :border="false">
        <van-cell v-for="(item,index) in menu.list1" :key="index" :title="item.name" :icon="item.icon" :value="item.value" size="large" :is-link="!item.value" @tap="gotoPage(item.href)" />
      </van-cell-group>
      <view class="p-a-8"></view>
      <van-cell-group :border="false">
        <van-cell v-for="(item,index) in menu.list2" :key="index" :title="item.name" :icon="item.icon" :value="item.value" size="large" :is-link="!item.value" @tap="gotoPage(item.href)" />
      </van-cell-group>
      <view class="p-a-8"></view>
      <van-cell-group :border="false">
        <van-cell v-for="(item,index) in menu.list3" :key="index" :title="item.name" :icon="item.icon" :value="item.value" size="large" :is-link="!item.value" @tap="gotoPage(item.href)" />
      </van-cell-group>
    </view>
    <view class="p-a-15" v-if="user_info.userName != '请先登录'">
      <van-button size="large" round block @tap="loginOut">退出登录</van-button>
    </view>
  </view>
</template>

<script>
export default {
  data(){
    return{
      access_token: null,
      user_info:{
        avatar: null,
        userName: '请先登录',
        phone: '13800138000',
      },
      user_property: {},
      menu:{
        list1: [
          {
            href: '/packageA/cust/index',
            name: '我的车辆',
            icon: this.$icon.myvisitor,
          },
          {
            href: '/packageA/doctor/index',
            name: '结算单',
            icon: this.$icon.mydoctor
          },
          {
            href: '/packageA/doctor/index',
            name: '合同与协议',
            icon: this.$icon.mydoctor
          }],
        list2:[
          {
            href: '/packageA/doctor/index',
            name: '修改密码',
            icon: this.$icon.mydoctor
          },
          {
            href: '/packageA/doctor/index',
            name: '使用帮助',
            icon: this.$icon.mydoctor
          },
          {
            href: '/packageA/doctor/index',
            name: '意见反馈',
            icon: this.$icon.mydoctor
          }],
        list3:[
          {
            href: '/packageA/integral/index',
            name: '版本信息',
            icon: this.$icon.version,
            value: '1.0.0'
          },
        ]
      }
    }
  },
  onShow(){
    let vipInfo = this.$store.getters.vipInfo;
    if(vipInfo){
      this.user_info = vipInfo;
    }else{
      this.user_info.userName = '请先登录';
      this.user_info.phone = '手机号';
    }
  },
  methods:{
    gotoPage(href){
      if(this.$utils.checkLogin()){
        if(href == '#'){
          uni.showToast({title: '功能未开放！', icon: 'none'});
          return;
        }
        if(href == 'scan'){
          this.scan();
          return;
        }
        if(href == 'contact'){
          this.toService();
          return;
        }
        uni.navigateTo({
          url: href
        });
      }
    },
    loginOut(){
      this.$utils.gotoLogin('确定要退出？');
    },
    scan(){
        uni.scanCode({
          success: (res) => {
            if(res.scanType == 'WX_CODE' && res.path) {
              let path = decodeURIComponent(res.path)
              uni.navigateTo({url:'/'+path})
            }
          }
      })
    },
    toService() {
				uni.showModal({
					title: "提示",
					content: "点击确认拨打电话给人工客服",
					success: res => {
						if (res.confirm) {
							uni.makePhoneCall({
								phoneNumber: "17665459508",
								success: res => {
									console.log(res)
								}
							})
						}
					}
				})
			},
  }
}
</script>

<style>

</style>